<template>
  <v-layout class="release-container" justify-start align-start wrap>
    <v-flex md12 text-xs-left>
      <v-btn flat round @click="$router.go(-1)">
        <ui-icon icon="angle-left fa-lg"></ui-icon>
        <!-- <v-icon>keyboard_arrow_left</v-icon> -->
        <div class="ml-2">返回</div>
      </v-btn>
    </v-flex>
    <v-flex md12 text-xs-left pl-5>
      <span class="headline">店铺审核</span>
    </v-flex>
    <v-flex md6 pt-4>
      <v-layout justify-start align-center wrap px-5>
        <v-flex md12 mt-4 d-flex align-center justify-start>
          <!-- 充值金额 -->
          <v-flex md4>
            <span class="subTitle title-color">店铺名称</span>
          </v-flex>

          <v-flex md8>
            <v-text-field type="text" disabled solo v-model="shop.shopName" hide-details></v-text-field>
          </v-flex>
        </v-flex>

        <!-- <v-flex md12 mt-4 d-flex align-center justify-start>
          <v-flex md4>
            <span class="subTitle title-color">店铺类目</span>
          </v-flex>

          <v-flex md8>
            <v-select solo :items="categories" v-model="shop.category" disabled></v-select>
          </v-flex>
        </v-flex> -->

        <v-flex md12 mt-4 d-flex align-center justify-start>
          <!-- 充值金额 -->
          <v-flex md4>
            <span class="subTitle title-color">店铺链接</span>
          </v-flex>

          <v-flex md8>
            <v-text-field type="text" solo v-model="shop.interlinkage" disabled hide-details></v-text-field>
          </v-flex>
        </v-flex>

        <v-flex md12 mt-4 d-flex align-center justify-space-between>
          <!-- 充值方式 -->
          <v-flex md4>
            <span class="subTitle title-color">状态 *</span>
          </v-flex>

          <v-flex md8>
            <v-select solo :items="buyerStatus" v-model="shop.status"></v-select>
          </v-flex>
        </v-flex>

        <v-flex md12 mt-2 d-flex align-center justify-space-between>
          <!-- 交易流水号 -->
          <v-flex md4>
            <span class="subTitle title-color">备注</span>
          </v-flex>

          <v-flex md8>
            <v-textarea hide-details solo v-model="shop.checkExplains"></v-textarea>
          </v-flex>
        </v-flex>

        <v-flex md12 mt-4 d-flex align-center justify-center>
          <v-flex md4>
            <v-btn large round color="primary" @click="onSubmit">
              <span class="title">保存</span>
            </v-btn>
          </v-flex>
        </v-flex>
      </v-layout>
    </v-flex>
  </v-layout>
</template>


<script lang="ts">
// 使用类装饰器
import { Component, Vue } from "vue-property-decorator";
import { KV } from "@/utils/type";
import { Todo } from "@/api";
import { CheckCommon } from "@/api/bean";
import { TopupStatusKV, CategoryKV } from "@/utils/constants";
import Cookie from "js-cookie";
declare const $Vue: Vue;

@Component({})
export default class ShopAudit extends Vue {
  private defaultShop: any = {
    interlinkage: "",
    shopName: "",
    remark: "",
    platform: 1,
    category: 1
  };

  private buyerStatus: Array<KV> = TopupStatusKV.slice();

  private categories: Array<KV> = CategoryKV;

  private shop: any = {};

  private requiredFields: Array<string> = [
    "interlinkage",
    "shopName",
    "platform",
    "status",
  ];

  protected mounted() {
    // this.shop = Object.assign({}, this.defaultShop);
    this.shop = this.$route.params;
    this.getSingleShop();
  }

  private onSubmit() {
    if (!this.validate()) {
      return $Vue.$emit("snackbar", {
        message: "请填写必填字段"
      });
    }
    this.saveShopAudit();
  }

  private validate(): boolean {
    let pass = true;
    this.requiredFields.forEach((item: string) => {
      if (this.shop[item] === "") {
        pass = false;
      }
    });
    return pass;
  }

  /**
   * 获取
   */
  private async getSingleShop() {
    const params: any = {
      shopId: this.shop.shopId,
    };
    const { data } = await Todo.getSingleShop.r(params);
    console.log("getSingleShop", data);
    if (data.result === 0) {
      this.shop.checkType = data.data.checkType;
    } else {
      $Vue.$emit("snackbar", {
        message: data.message
      });
    }
  }

  private async saveShopAudit() {
    const params: CheckCommon = {
      foreignType: this.shop.checkType,
      foreignKeyId: this.shop.shopId,
      checkStatus: this.shop.status,
      checkExplains: this.shop.checkExplains,
      checkUserId: Number(Cookie.get("userId"))
    };
    const { data } = await Todo.saveAudit.r(params);
    console.log("saveShopAudit", data);
    $Vue.$emit("snackbar", {
      message: data.message
    });
    if (data.result === 0) {
      this.$router.go(-1);
    } else {
    }
  }
}
</script>

<style lang="less" scoped>
</style>


